﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.IsolatedStorage;
using System.IO;

namespace StaringLog
{
    class ImplemenitgLog
    {
        static void Main(string[] args)
        {

            //ReadFromLog();
            //WriteToLog();
            //ReadFromLog();
            WriteToSettings();
            ReadSettings();
            
        }

        private static void ReadSettings() 
        {
            Console.WriteLine(StartLog.Default.LastLog);
            StartLog.Default.LastLog = StartLog.Default.CurrentLog;
            StartLog.Default.Save();
        }

        private static void WriteToSettings() 
        {
            StartLog.Default.CurrentLog = DateTime.Now;
            StartLog.Default.Save();

        }

        private static void WriteToLog()
        {
            IsolatedStorageFile userStorage = IsolatedStorageFile.GetUserStoreForAssembly();
            using (userStorage)
            {
                IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("example.txt", System.IO.FileMode.OpenOrCreate, userStorage);
                using (isoStream)
                {
                    // Read the isolated storage file contents
                    StreamWriter writer = new StreamWriter(isoStream);
                    using (writer)
                    {
                        writer.WriteLine(DateTime.Now.ToString());
                    }
                }
            }
        }

        private static void ReadFromLog()
        {
            IsolatedStorageFile userStorage = IsolatedStorageFile.GetUserStoreForAssembly();
            using (userStorage)
            {
                IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("example.txt", System.IO.FileMode.Open, userStorage);
                using (isoStream)
                {

                    StreamReader reader = new StreamReader(isoStream);
                    using (reader)
                    {

                        string line = reader.ReadLine();
                        string previous = string.Empty;
                        while (line != null)
                        {
                            previous = line;
                            line = reader.ReadLine();
                        }

                        Console.WriteLine(previous);
                    }
                }
            }
        }
    }
}
